package com.veterinaria.dao;

import java.io.Reader;
import java.util.ArrayList;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.veterinaria.bean.EspecieBean;
import com.veterinaria.bean.ServicioBean;
import com.veterinaria.services.ServicioService;

public class ServicioDAO implements ServicioService{
	
	SqlSessionFactory sqlmapper= null;{
	   	 try {
	   	 Reader reader = Resources.getResourceAsReader("ConfiguracionIbatis.xml");
	   	 sqlmapper =new  SqlSessionFactoryBuilder().build(reader);
	   	 } catch (Exception e) {
				e.printStackTrace();
			}
	    }
	
	@Override
	public ArrayList<ServicioBean> listarServicios() throws Exception {
		ArrayList<ServicioBean> lista=new ArrayList<>();
		SqlSession session = sqlmapper.openSession();		
		try {			
			lista= (ArrayList<ServicioBean>)session.selectList("servicioxml.listarServicio");			
		} catch (Exception e) {
			e.printStackTrace();
		}finally{ session.close();}
		return lista;
	}

}
